//
//  CellForThreePIC.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/7/1.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "CellForThreePIC.h"
#import "PrefixHeader.pch"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "LoginOfVC.h"
#import "Settings.h"
@interface CellForThreePIC ()
@property(nonatomic, retain)UIImageView *UserPic;

@property(nonatomic, retain)UILabel *UserName;

@property(nonatomic, retain)UILabel *LableOfBottm;

@property(nonatomic, retain)UIImageView *FirstImg;

@property(nonatomic, retain)UIImageView *SecondImg;

@property(nonatomic, retain)UIImageView *ThirdImg;


@end


@implementation CellForThreePIC


- (void)dealloc{
    [_UserName release];
    [_UserPic release];
    [_LableOfBottm release];
    [_FirstImg release];
    [_SecondImg release];
    [_ThirdImg release];
    [_model release];
    
    [super dealloc];
    
    
    
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self creat];
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
    
    
}

- (void)creat{
    
    
    UIView *viewOfBackground = [[UIView alloc]init];
    
    viewOfBackground.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:viewOfBackground];
    
    [viewOfBackground mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView.mas_centerX);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.width.offset(SCREEN_WIDTH);
        make.height.equalTo(self);
    }];
    self.UserPic = [[UIImageView alloc]init];
    
//    _UserPic.backgroundColor = [UIColor redColor];
    
    [viewOfBackground addSubview:_UserPic];
    [[NSNotificationCenter defaultCenter]addObserverForName:@"changeBackgroundColor" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
        
        viewOfBackground.backgroundColor = [[Settings shareSettings]color:WhiteToGray];
        
    }];
    [_UserPic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewOfBackground.mas_top).offset(10);
        make.leading.equalTo(viewOfBackground.mas_leading).offset(10);
        make.height.equalTo(viewOfBackground).multipliedBy(1.0 / 3.0);
        make.width.equalTo(_UserPic.mas_height).multipliedBy(1);
        
    }];
    _UserPic.layer.cornerRadius = 29;
    _UserPic.layer.masksToBounds = YES;
    
    
    _UserName = [[UILabel alloc]init];
//    _UserName.backgroundColor = [UIColor greenColor];
    
    [viewOfBackground addSubview:_UserName];
    
    [_UserName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewOfBackground.mas_top).offset(18);
        make.leading.equalTo(_UserPic.mas_trailing).offset(10);
        make.height.offset(20);
        make.width.offset(SCREEN_WIDTH - 190);
        NSLog(@"%f", _UserPic.frame.size.width);
    }];
    
    _LableOfBottm = [[UILabel alloc]init];
    

    
    [viewOfBackground addSubview:_LableOfBottm];
    
    [_LableOfBottm mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_UserName);
        make.top.equalTo(_UserName.mas_bottom).offset(5);
        make.height.equalTo(_UserName);
        make.width.equalTo(_UserName);
        
    }];
    
    _FirstImg = [[UIImageView alloc]init];
    
    
    
    [viewOfBackground addSubview:_FirstImg];
    
    [_FirstImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_UserPic.mas_bottom).offset(9);
        make.leading.equalTo(viewOfBackground.mas_leading).offset(0);
        make.width.offset((SCREEN_WIDTH - 2) / 3);
        CGFloat h = viewOfBackground.frame.size.height / 3;
        NSLog(@"%f", h);
        make.height.equalTo(self).multipliedBy(1.0 / 1.8);
    }];
    
    _SecondImg = [[UIImageView alloc]init];
    
    
    
    [viewOfBackground addSubview:_SecondImg];

    [_SecondImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_FirstImg.mas_centerY);
        make.leading.equalTo(_FirstImg.mas_trailing).offset(1);
        make.width.equalTo(_FirstImg.mas_width);
        make.height.equalTo(_FirstImg.mas_height);
        
    }];
    
    _ThirdImg = [[UIImageView alloc]init];
    
   
    
    [viewOfBackground addSubview:_ThirdImg];
    
    [_ThirdImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_FirstImg.mas_centerY);
        make.leading.equalTo(_SecondImg.mas_trailing).offset(1);
        make.width.equalTo(_SecondImg);
        make.height.equalTo(_SecondImg);
    }];
    
    UIView *viewOfButton = [[UIView alloc]init];
    viewOfButton.backgroundColor = [UIColor colorWithRed:0.0 / 256.0f  green:208.0 / 256.0f blue:252.0 / 256.0f alpha:1];
    [viewOfBackground addSubview:viewOfButton];
    [viewOfButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_UserPic.mas_centerY);
        make.leading.equalTo(_LableOfBottm.mas_trailing).offset(8);
        make.width.offset(80);
        make.height.equalTo(viewOfButton.mas_width).multipliedBy(1.0 / 3);
    }];
    viewOfButton.layer.cornerRadius = 5;
    _button = [UIButton buttonWithType:UIButtonTypeSystem];
    _button.backgroundColor = [UIColor whiteColor];
    
    
    [viewOfButton addSubview:_button];
    
    [_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(viewOfButton.mas_leading).offset(0.8);
        make.top.equalTo(viewOfButton.mas_top).offset(0.8);
        make.width.equalTo(viewOfButton.mas_width).offset(- 1.6);
        make.height.equalTo(viewOfButton.mas_height).offset( -1.6);
        
    }];
    [_button setTitle:@"+关注" forState:UIControlStateNormal];
    _button .titleLabel.font = [UIFont systemFontOfSize:14];
    [_button setTintColor:[UIColor colorWithRed:0.0 / 256.0f  green:208.0 / 256.0f blue:252.0 / 256.0f alpha:1]];
    _button.layer.cornerRadius = 4;
    
    
    [viewOfButton release];
    [_UserPic release];
    [_UserName release];
    [_LableOfBottm release];
    [_FirstImg release];
    [_SecondImg release];
    [_ThirdImg release];
    
    
}



- (void)setModel:(ExpertModel *)model{
    [self.UserPic sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:nil];
    
    self.UserName.font = [UIFont systemFontOfSize:15];
    self.UserName.text = model.nick_name;
    NSString *str1 = @"图文教程 | ";
    NSString *str2 = @"视频教程 | ";
    NSString *str3 = @"资源";
    self.LableOfBottm.font = [UIFont systemFontOfSize:11];
    self.LableOfBottm.textColor = [UIColor grayColor];
    self.LableOfBottm.text = [[[[[model.course_count stringByAppendingString:str1]stringByAppendingString:model.video_count]stringByAppendingString:str2]stringByAppendingString:model.opus_count]stringByAppendingString:str3];
    NSLog(@"%ld", model.list.count);
    
    for (int i = 0; i < model.list.count; i++)
    {
        if (i == 0)
        {
            NSURL *url = [model.list[i]objectForKey:@"host_pic"];
            [self.FirstImg sd_setImageWithURL:url placeholderImage:nil];
        }
        else if(i == 1)
        {
           NSURL *url = [model.list[i]objectForKey:@"host_pic"];
            [self.SecondImg sd_setImageWithURL:url placeholderImage:nil];
        }
        else if(i == 2)
        {
            
            NSURL *url = [model.list[i]objectForKey:@"host_pic"];
            [self.ThirdImg sd_setImageWithURL:url placeholderImage:nil];

        }
    }
    
//    [self.FirstImg sd_setImageWithURL:[NSURL URLWithString:model.host_pic] placeholderImage:nil];
    
}

@end
